﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Configuration;  /// Use configurationfile.


namespace SqlAdminBackup
{
    class Program
    {
        static void Main(string[] args)
        {
					string cnnstr = ConfigurationManager.ConnectionStrings["cnnstrSqlAdmin"].ConnectionString;
					try { new Parameters(); }
					catch (Exception e) { throw e; }
        }

        /// <summary>
        /// Generate a collection of selected databases based on the given filter. Uses statement parameter "DatabaseName".
        /// </summary>
        /// <param name="DatabaseFilter"></param>
        string[] Database_Select(string DatabaseFilter)
        {
					return null;
        }

    }

		/// <summary>
		/// Database backup
		/// </summary>
		class Backup
		{
			private string _databasename;
			string DatabaseName
			{
				get { return _databasename; }
				set { _databasename = value; }
			}

			private string _backuptype;
			string Type
			{
				get { return _backuptype; }
				set
				{
					switch (value.ToUpper())
					{
						case "FULL":
							_backuptype = "FULL";
							break;
						case "DIFF":
							_backuptype = "DIFF";
							break;
						case "LOG":
							_backuptype = "LOG";
							break;
						default:
							throw new System.ArgumentException("The given backup type is not valid.");
					}
				}
			}

			private string _backupfilename;
			string FileName
			{
				get { return _backupfilename; }
				set { _backupfilename = this.DatabaseName + '_' + this.Type; }
			}

			public Backup(string DbName)
			{
				DatabaseName = DbName;
			}

			/// <summary>
			/// Execute database backup.
			/// </summary>
			private void Execute()
			{
			}

			/// <summary>
			/// Verify database backup.
			/// </summary>
			private void Verify()
			{
			}

			/// <summary>
			/// Generate T-SQL database restore script.
			/// </summary>
			public void RestoreScript()
			{
				string RestoreSql = "RESTORE DATABASE [" + this.DatabaseName + "]" +
					" FROM DISK=N''" +
					" WITH RECOVERY;";

				System.Console.Write(RestoreSql);
			}
		}

		/// <summary>
		/// Command line parameters. Parse, check and assign values to attributes.
		/// </summary>
		class Parameters
		{
			private string[] _args;

			public Parameters()
			{
				string[] CmdLnArgs = System.Environment.GetCommandLineArgs();

				if (CmdLnArgs.Length == 0)
				{
					throw new System.ArgumentException("Command line parameters are required.");
				}

				_args = CmdLnArgs;

				foreach (string cmd_arg in _args)
				{
					if (cmd_arg[0] != '-')
					{ throw new System.ArgumentException("All argument names must be prefixed by '-'."); }
				}
			}

			/// <summary>
			/// Check statement parameters.
			/// </summary>
			private static void Check()
			{
			}

			/// <summary>
			/// Show command line help.
			/// </summary>
			private static void Help()
			{
				Console.WriteLine("SqlAdminBackup.exe ...");
			}
		}
}
